
const Acan = require('../../libs/Acan')
const errors = require('@feathersjs/errors')

module.exports = {
  before: {
    all: [],
    find: [],
    get: [],
    create: [ d=> {
      let post = d.data
      let error
      let codes = ['name', 'gateway']
      let zhrr = ['应用名称', '应用网关']
      codes.forEach((v, i)=> {
        if (error) return
        if (!post[v]) return error = new errors.BadRequest('请输入' + zhrr[i], {param: v})
        // if (rules[v]) error = rules[v](post)
      })
      if (error) return Promise.reject(error)

      const crypto = require('crypto')
      const hash = crypto.createHash('sha256')
      hash.update(post.name + (new Date()).getTime())
      post.secret = hash.digest('hex')

    }],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
}
